<!DOCTYPE html>
 <html>
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
      <title>Autobahn: PubSub with Authorization</title>

      <!-- include AutobahnJS .. that's all you need -->
      <script src="http://autobahn.s3.amazonaws.com/js/autobahn.min.js"></script>

      <script>
         // WAMP session object
         var sess;

         window.onload = function() {

            // connect to WAMP server
            ab.connect("ws://localhost:9000",

               // WAMP session was established
               function (session) {

                  sess = session;
                  console.log("Connected!");

                  sess.prefix("event", "http://example.com/event/");
                  sess.subscribe("event:simple", onEvent);
                  sess.subscribe("event:simple-foobar", onEvent);
                  sess.subscribe("event:foobar1", onEvent);
                  sess.subscribe("event:foobar2", onEvent);
               },

               // WAMP session is gone
               function (code, reason) {

                  sess = null;
                  alert(reason);
               }
            );
         };

         function onEvent(topicUri, event) {
            console.log(topicUri);
            console.log(event);
         }

         function logerror(erroruri, errordesc) {
            console.log(erroruri + ' ("' + errordesc + '")');
         }

         function test()
         {
            sess.publish("event:simple", {name: "foo",
                                          created: new Date(),
                                          num: 23,
                                          rand: Math.random()});

            sess.publish("event:simple-foobar", {name: "foo",
                                                 value: "bar",
                                                 num: 333});

            sess.publish("event:foobar1", {count: 42});
            sess.publish("event:foobar1", {count: -1});
            sess.publish("event:foobar2", {count: 666});
            sess.publish("event:foobarbaz", {count: 10});
         }
     </script>
   </head>
   <body>
      <h1>Autobahn: PubSub with Authorization</h1>
      <button onclick="test()">Publish Events</button>
   </body>
 </html>
